home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
ARASAN_S.ZIP
/
SQUARE.H
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-19
|
2KB
|
129 lines
// Copyright 1994 by Jon Dart. All Rights Reserved.
#ifndef _SQUARE_H
#define _SQUARE_H
#include <assert.h>
#include "types.h"
#include "color.h"
class Square;
class Square
{
public:
friend Square operator +( const Square &sq, const int i);
friend Square operator -( const Square &sq, const int i);
enum {InvalidSquare = 127};
Square()
{
my_location = InvalidSquare;
}
Square( const int location )
{
my_location = location;
}
Square( const int file, const int rank, const ColorType side );
operator int() const
{
return my_location;
}
Square &operator +=( const int i)
{
my_location += i;
return *this;
}
Square &operator -=( const int i)
{
my_location -= i;
return *this;
}
Square &operator ++()
{
my_location++;
return *this;
}
Square &operator --()
{
my_location--;
return *this;
}
int Rank( const ColorType side = White) const;
// returns "rank" from the perspective of "side". 1 = 1st
// rank for side, 8 = last rank.
int File() const
{
return Files[my_location];
}
// returns file. Queen rook file = 1, King rook file = 8.
Boolean OnBoard() const
{
return (my_location & ~0x3f) == 0;
}
Boolean OnEdge() const
{
return Edge[my_location];
}
// invalid value, used as delimiter
static const Square &Invalid();
Boolean IsInvalid() const
{
return my_location == InvalidSquare;
}
void SetInvalid()
{
my_location = InvalidSquare;
}
ColorType Color() const
{
return (ColorType)Colors[my_location];
}
static Square Value( char *p);
// Parse a square value in algebraic notation (e.g. "g7") and
// return a corresponding Square type.
char FileImage() const;
char RankImage() const;
private:
byte my_location;
static int Files[64];
static int Ranks[64];
static int Edge[64];
static int Colors[64];
};
inline Square operator +( const Square &sq, const int i)
{
return Square(sq.my_location + i);
}
inline Square operator -( const Square &sq, const int i)
{
return Square(sq.my_location-i);
}
#endif